package cn.szq.concurrent.thread.stop;

/**
 * @ClassName: StopDuringSleep
 * @Description:
 * @Author: szq
 * @Date: 2021-09-26 16:02:51
 */
public class StopDuringSleep {

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = ()->{
            int num = 0;
            try{
                while (!Thread.currentThread().isInterrupted() && num <= 1000){
                    System.out.println(num);
                    num ++;
                    Thread.sleep(1000000);
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        };

        Thread thread = new Thread(runnable);
        thread.start();
        Thread.sleep(5);
        thread.interrupt();
    }
}
